from threading import Thread, Lock

task_lock = Lock()


def task(name: str):
    global task_lock
    for n in range(6):
        task_lock.acquire()  # 上锁
        print(f"{name} - round {n} - step 1\n", end="")
        print(f"{name} - round {n} - step 2\n", end="")
        print(f"{name} - round {n} - step 3\n", end="")
        task_lock.release()  # 释放
        # 确保 中间那部分 作为整体 全部执行完毕
        # 避免线程问题 如数据冲突


t1 = Thread(target=task, args=("A",))
t2 = Thread(target=task, args=("B",))
t3 = Thread(target=task, args=("C",))

t1.start()
t2.start()
t3.start()


